package test0; /**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2023-03-29
 * Time: 14:51
 */
import java.util.*;

//https://www.nowcoder.com/practice/839f681bf36c486fbcc5fcb977ffe432?tpId=122&tqId=33666&ru=/exam/oj
public class Main2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        String[] strs = new String[n];
        int[] length = new int[n];
        int a = 1;
        int b = 1;
        for (int i = 0; i < n; i++) {
            strs[i] = scanner.next();
            length[i] = strs[i].length();
        }
        for (int i = 0; i < n - 1; i++) {
            if (length[i] > length[i + 1]) {
                a = 0;
                break;
            }
        }
        if (!isDictionarySort(strs)) {
            b = 0;
        }
        if (a + b == 2) {
            System.out.println("both");
        } else {
            if (a == 1) {
                System.out.println("lengths");
            } else if (b == 1) {
                System.out.println("lexicographically");
            } else {
                System.out.println("none");
            }
        }
    }


//判断是否是字典排序
    public static boolean isDictionarySort(String[] strs) {
        int n = strs.length;
        if (n == 1) {
            return true;
        }
        for (int i = 0; i < n - 1; i++) {
            int sl1 = strs[i].length();
            int sl2 = strs[i + 1].length();
            int sl = Math.min(sl1,sl2);
            int j = 0;
            for ( j = 0; j < sl;) {
                if (strs[i].charAt(j) > strs[i + 1].charAt(j)) {
                    return false;
                } else if (strs[i].charAt(j) == strs[i + 1].charAt(j)) {
                    j++;
                } else {
                    break;
                }
            }
            if (j == sl  && sl1 > sl2) {
                return false;
            }
        }
        return true;
    }
}
